﻿using Abp.Linq.Expressions;
using Common.Enums;
using Entity.Enums;
using Entity.Models.dto;
using Entity.Models.Entities;
using Entity.Models.vo;
using IBLL;
using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using utils.enums;
using utils.Enums;
using utils.EX;
using Utils;

namespace BLL
{
    /// <summary>
    /// 工作流步骤BLL层
    /// </summary>
    public class WorkFlow_InstanceStepBLL : IWorkFlow_InstanceStepBLL
    {
        /// <summary>
        /// 数据库上下文
        /// </summary>
        RepositorySysContext _dbsysContext;
        /// <summary>
        /// 工作流步骤DAL接口
        /// </summary>
        IWorkFlow_InstanceStepDAL _workFlow_InstanceSetpDal;

        /// <summary>
        /// 用户DAL接口
        /// </summary>
        IUserDAL _userDAL;

        /// <summary>
        /// 耗材记录
        /// </summary>
        IConsumableRecordDAL _consumableRecordDAL;

        /// <summary>
        /// 工作流模板
        /// </summary>
        IWorkFlow_ModelDAL _workFlow_ModelDal;

        /// <summary>
        /// 工作流实例
        /// </summary>
        IWorkFlow_InstanceDAL _workFlow_InstanceDAL;
        /// <summary>
        /// 耗材信息DAL
        /// </summary>
        IConsumableInfoDAL _consumableInfoDAL;

        /// <summary>
        /// 用户角色
        /// </summary>
        IR_UserInfo_RoleInfoDAL _r_UserInfo_RoleInfoDAL;

        /// <summary>
        /// 角色
        /// </summary>
        IRoleInfoDAL _roleInfoDAL;

        //构造
        public WorkFlow_InstanceStepBLL(IWorkFlow_InstanceStepDAL workFlow_Instance, IUserDAL userDAL,
            IWorkFlow_ModelDAL workFlow_ModelDal, IWorkFlow_InstanceDAL workFlow_InstanceDAL,
            IConsumableInfoDAL consumableInfoDAL, IR_UserInfo_RoleInfoDAL r_UserInfo_RoleInfoDAL,
            IRoleInfoDAL roleInfoDAL, RepositorySysContext dbsysContext,
            IConsumableRecordDAL consumableRecordDAL)
        {
            _workFlow_InstanceSetpDal = workFlow_Instance;
            _userDAL = userDAL;
            _workFlow_ModelDal = workFlow_ModelDal;
            _workFlow_InstanceDAL = workFlow_InstanceDAL;
            _consumableInfoDAL = consumableInfoDAL;
            _r_UserInfo_RoleInfoDAL = r_UserInfo_RoleInfoDAL;
            _roleInfoDAL = roleInfoDAL;
            _dbsysContext = dbsysContext;
            _consumableRecordDAL = consumableRecordDAL;
        }

        /// <summary>
        /// 工作流步骤数据列表、搜索
        /// </summary>
        /// <param name="workFlow_InstanceName">工作流步骤名称</param>
        /// <param name="page">页数</param>
        /// <param name="limit">数据条数</param>
        /// <returns></returns>
        public List<WorkFlow_InstanceStepDTO> getworkFlow_InstanceStepList(string userId, string workFlow_InstanceName, string page, string limit, out int cont)
        {
            //连表
            IQueryable<WorkFlow_InstanceStepDTO> datas = Linked(userId, null);

            if (!string.IsNullOrEmpty(workFlow_InstanceName))
            {
                datas = datas.Where(i => i._reviewStatus.Contains(workFlow_InstanceName));
            }
            //分页
            var pagedepartment = datas.OrderByDescending(d => d._createTimes).Skip((int.Parse(page) - 1) * int.Parse(limit)).Take(int.Parse(limit)).ToList();
            cont = datas.Count();

            //整合数据
            List<WorkFlow_InstanceStepDTO> departmentList = new List<WorkFlow_InstanceStepDTO>();
            foreach (var item in pagedepartment)
            {
                departmentList.Add(new WorkFlow_InstanceStepDTO(item));
            }

            return departmentList;
        }

        /// <summary>
        /// 连表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="instanceSteID"></param>
        /// <returns></returns>
        private IQueryable<WorkFlow_InstanceStepDTO> Linked(string userId, string instanceSteID)
        {
            IQueryable<WorkFlow_InstanceStep> workFlow_InstanceStep = _workFlow_InstanceSetpDal.getEntitys();
            workFlow_InstanceStep = instanceSteID != null ? workFlow_InstanceStep.Where(w => w.Id.EndsWith(instanceSteID)) : workFlow_InstanceStep.Where(w => w.ReviewerId.EndsWith(userId));
            //连表
            var datas = from d in workFlow_InstanceStep
                        join w in _workFlow_InstanceDAL.getEntitys()//工作流实例
                        on d.InstanceId equals w.Id
                        into Temedw
                        from wi in Temedw.DefaultIfEmpty()

                        join w in _workFlow_ModelDal.getEntitys().Where(u => u.IsDelete != true)//工作流模板
                        on wi.ModelId equals w.Id
                        into Tempwm
                        from ww in Tempwm.DefaultIfEmpty()

                        join c in _consumableInfoDAL.getEntitys().Where(u => u.IsDelete != true)//耗材信息
                        on wi.OutGoodsId equals c.Id
                        into Tempwc
                        from cc in Tempwc.DefaultIfEmpty()


                        join u in _userDAL.getUserShowDAL().Where(u => u.IsDelete != true)//用户
                        on wi.Creator equals u.Id
                        into Tempwu
                        from uu in Tempwu.DefaultIfEmpty()
                        select new WorkFlow_InstanceStepDTO
                        {
                            Id = d.Id,
                            _instanceId = ww.Title,
                            _consumableName = cc.ConsumableName,
                            _reviewerName = uu.UserName,
                            _reviewReason = d.ReviewReason,
                            _instanceIds = wi.Id,
                            _reviewStatus = Enums.getDescribe(d.ReviewStatus),
                            _reviewTimes = d.ReviewTime,
                            _outNum = wi.OutNum,
                            _beforeStepId = d.BeforeStepId,
                            _updataStuaus = d.ReviewerId.EndsWith(uu.Id),
                            _createTimes = d.CreateTime,
                        };
            return datas;
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reviewReason"></param>
        /// <param name="reviewStatusb"></param>
        /// <returns></returns>
        public bool UpdataWorkFlow_InstanceStep(string id, string reviewReason, string userId, int num, WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums reviewStatusb)
        {
            //打开事务
            using (var Transaction = _dbsysContext.Database.BeginTransaction())
            {
                //发起人再次申请 

                //审核
                WorkFlow_InstanceStep workFlow_InstanceStep = Audit(id, reviewReason, userId, reviewStatusb, Transaction);
                //根据登录人发起下级审核
                ReviewTheLogic(userId, num, reviewStatusb, Transaction, workFlow_InstanceStep);
                //提交事务
                Transaction.Commit();
            }
            return true;
        }

        /// <summary>
        /// 根据登录人发起下级审核
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="num"></param>
        /// <param name="reviewStatusb"></param>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void ReviewTheLogic(string userId, int num, WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums reviewStatusb, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            //根据登录人id获取角色
            List<string> rolename = (from ru in _r_UserInfo_RoleInfoDAL.getEntitys().Where(ru => ru.UserId.EndsWith(userId))
                                     join r in _roleInfoDAL.getEntitys().Where(r => r.IsDelete != true)
                                    on ru.RoleId equals r.Id
                                     select r.RoleName).ToList();

            if (rolename.Contains("部门经理"))
            {
                DepartmentManager(reviewStatusb, Transaction, workFlow_InstanceStep);
            }
            else if (rolename.Contains("仓库管理"))
            {
                StoreManagement(userId, reviewStatusb, Transaction, workFlow_InstanceStep);
            }
            else if (rolename.Contains("普通员工"))
            {
                GeneralStaff(num, Transaction, workFlow_InstanceStep);
            }
            else
            {
                Transaction.Rollback();
                throw new MyException(1003, "没有权限");
            }
        }

        /// <summary>
        /// 普通员工
        /// </summary>
        /// <param name="num"></param>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void GeneralStaff(int num, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            //修改实例信息
            WorkFlow_Instance workFlow_Instance = _workFlow_InstanceDAL.getEntitys().FirstOrDefault(w => w.Id.EndsWith(workFlow_InstanceStep.InstanceId));
            workFlow_Instance.OutNum = num;
            if (_workFlow_InstanceDAL.UpdataEntity(workFlow_Instance) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1063, "修改申请数量失败");
            }

            //再次发起申请 
            string reviewerId = _workFlow_InstanceSetpDal.getEntitys().Where(w => w.Id.EndsWith(workFlow_InstanceStep.BeforeStepId)).Select(w => w.ReviewerId).FirstOrDefault();
            if (string.IsNullOrEmpty(reviewerId))
            {
                Transaction.Rollback();
                throw new MyException(1053, "找不到审核人");
            }
            if (_workFlow_InstanceSetpDal.AddEntity(new WorkFlow_InstanceStep(workFlow_InstanceStep, reviewerId)) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1083, "发起审核失败");
            }
        }

        /// <summary>
        /// 部门经理
        /// </summary>
        /// <param name="reviewStatusb"></param>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void DepartmentManager(WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums reviewStatusb, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.AGREE == reviewStatusb) //同意
            {
                ManagerAgree(Transaction, workFlow_InstanceStep);
            }
            else if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.REJECTED == reviewStatusb) //驳回
            {
                //获取申请人信息
                string Creator = _workFlow_InstanceDAL.getEntitys().Where(w => w.Id.EndsWith(workFlow_InstanceStep.InstanceId)).Select(w => w.Creator).FirstOrDefault();
                if (string.IsNullOrEmpty(Creator))
                {
                    Transaction.Rollback();
                    throw new MyException(1039, "找不到上一实例申请人");
                }
                if (_workFlow_InstanceSetpDal.AddEntity(new WorkFlow_InstanceStep(workFlow_InstanceStep, Creator)) < 1)
                {
                    Transaction.Rollback();
                    throw new MyException(1049, "驳回失败");
                }
            }
            else
            {
                Transaction.Rollback();
                throw new MyException(1029, "错误操作");
            }
        }

        /// <summary>
        /// 经理（同意）
        /// </summary>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void ManagerAgree(Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            var ids = (from r in _roleInfoDAL.getEntitys().Where(r => r.RoleName.EndsWith("仓库管理"))
                       join ur in _r_UserInfo_RoleInfoDAL.getEntitys()
                       on r.Id equals ur.RoleId
                       join u in _userDAL.getUserShowDAL()
                       on ur.UserId equals u.Id
                       select u.Id).FirstOrDefault();
            //仓库管理员审核 
            if (string.IsNullOrEmpty(ids))
            {
                Transaction.Rollback();
                throw new MyException(1006, "没有仓库管理");
            }
            //保存
            if (_workFlow_InstanceSetpDal.AddEntity(new WorkFlow_InstanceStep(workFlow_InstanceStep, ids)) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1008, "审核失败");
            }
        }

        /// <summary>
        /// 仓库管理（审核）
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="reviewStatusb"></param>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void StoreManagement(string userId, WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums reviewStatusb, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.AGREE == reviewStatusb) //同意
            {
                WarehouseAgree(userId, Transaction, workFlow_InstanceStep);
            }
            else if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.REJECTED == reviewStatusb) //驳回
            {
                //根据步骤上一id获取
                WorkFlow_InstanceStep workFlow_Instance = _workFlow_InstanceSetpDal.getEntitys().FirstOrDefault(w => w.Id.EndsWith(workFlow_InstanceStep.BeforeStepId));
                if (_workFlow_InstanceSetpDal.AddEntity(new WorkFlow_InstanceStep(workFlow_Instance, workFlow_Instance.ReviewerId)) < 1)
                {
                    Transaction.Rollback();
                    throw new MyException(1023, "驳回失败");
                }
            }
            else
            {
                Transaction.Rollback();
                throw new MyException(1009, "错误操作");
            }
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reviewReason"></param>
        /// <param name="userId"></param>
        /// <param name="reviewStatusb"></param>
        /// <param name="Transaction"></param>
        /// <returns></returns>
        private WorkFlow_InstanceStep Audit(string id, string reviewReason, string userId, WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums reviewStatusb, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction)
        {
            WorkFlow_InstanceStep workFlow_InstanceStep = _workFlow_InstanceSetpDal.getEntitys().FirstOrDefault(w => w.Id.EndsWith(id));
            if (workFlow_InstanceStep == null)
            {
                Transaction.Rollback();
                throw new MyException(1005, "申请信息为空");
            }
            workFlow_InstanceStep.ReviewStatus = reviewStatusb;
            workFlow_InstanceStep.ReviewReason = reviewReason;
            workFlow_InstanceStep.ReviewTime = DateTime.Now;
            if (_workFlow_InstanceSetpDal.UpdataEntity(workFlow_InstanceStep) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1002, "审核失败");
            }

            if (workFlow_InstanceStep.ReviewerId != userId)
            {
                Transaction.Rollback();
                throw new MyException(1001, "没有权限");
            }

            return workFlow_InstanceStep;
        }

        /// <summary>
        /// 仓库管理员（同意）
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="Transaction"></param>
        /// <param name="workFlow_InstanceStep"></param>
        private void WarehouseAgree(string userId, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction Transaction, WorkFlow_InstanceStep workFlow_InstanceStep)
        {
            //获取当前工作步骤实例
            WorkFlow_Instance workFlow_Instance = _workFlow_InstanceDAL.getEntitys().FirstOrDefault(w => w.Id.EndsWith(workFlow_InstanceStep.InstanceId));
            //判断实例是否为空 
            if (workFlow_Instance == null)
            {
                Transaction.Rollback();
                throw new MyException(1006, "找不到工作流实例");
            }
            //修改
            workFlow_Instance.Status = WorkFlow_InstanceEnums.WorkFlow_InstanceEnumStatus.END;
            if (_workFlow_InstanceDAL.UpdataEntity(workFlow_Instance) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1008, "结束工作流失败");
            }

            //修改库存
            ConsumableInfo consumableInfo = _consumableInfoDAL.getByEntityId(workFlow_Instance.OutGoodsId);
            if (consumableInfo == null)
            {
                Transaction.Rollback();
                throw new MyException(1010, "找不到耗材信息");
            }
            if (consumableInfo.Num < workFlow_Instance.OutNum)
            {
                Transaction.Rollback();
                throw new MyException(1012, "库存不足");
            }
            //修改
            consumableInfo.Num -= workFlow_Instance.OutNum;
            if (_consumableInfoDAL.UpdataEntity(consumableInfo) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1014, "修改库存失败");
            }

            //添加一条出库记录
            if (_consumableRecordDAL.AddEntity(new ConsumableRecord(consumableInfo.Id, userId, workFlow_Instance.OutNum, 2)) < 1)
            {
                Transaction.Rollback();
                throw new MyException(1016, "更新出库记录失败");
            }
        }

        /// <summary>
        /// 步骤条
        /// </summary>
        /// <param name="instanceId">实例id</param>
        /// <returns></returns>
        public object geStepList(string instanceId)
        {
            //获取用户发起实例信息
            var Instance = _workFlow_InstanceDAL.getEntitys().Where(w => w.Id.EndsWith(instanceId)).Select(w => new { w.Reason, w.Creator }).FirstOrDefault();
            //获取用户信息
            if (Instance == null)
            {
                return null;
            }
            //获取当前实例创建人
            string userName = _userDAL.getUserShowDAL().Where(u => u.Id.EndsWith(Instance.Creator)).Select(u => u.UserName).FirstOrDefault();

            //数据集
            StepVos stepVos = new StepVos();
            int status = 0;

            //子数据集
            List<StepVo> steps = new List<StepVo>();

            //发起实例人的信息       
            steps.Add(new StepVo($"用户发起 [ {userName} ]", $" [理由] {Instance.Reason}"));
            stepVos.Status = status+=1;


            //获取当前步骤下所有步骤信息
            List<Text> a = (from w in _workFlow_InstanceSetpDal.getEntitys().Where(w => w.InstanceId.EndsWith(instanceId))
                            join ur in _r_UserInfo_RoleInfoDAL.getEntitys()
                             on w.ReviewerId equals ur.UserId
                            join ru in _roleInfoDAL.getEntitys()
                            on ur.RoleId equals ru.Id
                            select new Text
                            {
                                RoleName = ru.RoleName,
                                UserId = w.ReviewerId,
                                InstanceSetId = w.Id,
                                CreateTime = w.CreateTime,
                            }
                     ).ToList();

            //部门经理
            List<Text> managers = new List<Text>();

            //仓库管理
            List<Text> warehouses = new List<Text>();

            //普通员工
            List<Text> staffs = new List<Text>();
            foreach (var item in a)
            {
                if (item.RoleName.EndsWith("部门经理"))
                {
                    managers.Add(new Text(item.RoleName, item.UserId, item.CreateTime, item.InstanceSetId));
                }
                else if (item.RoleName.EndsWith("仓库管理"))
                {
                    warehouses.Add(new Text(item.RoleName, item.UserId, item.CreateTime, item.InstanceSetId));
                }
                else if (item.RoleName.EndsWith("普通员工"))
                {
                    staffs.Add(new Text(item.RoleName, item.UserId, item.CreateTime, item.InstanceSetId));
                }
            }

            //普通员工
            Text staff = staffs.OrderByDescending(r => r.CreateTime).FirstOrDefault();
            if (staff != null)
            {
                steps.Remove(steps.First());
                WorkFlow_InstanceStep workFlow_Instance = _workFlow_InstanceSetpDal.getEntitys().FirstOrDefault(w => w.Id.EndsWith(staff.InstanceSetId));
                //获取普通员工
                string userNames = _userDAL.getUserShowDAL().Where(u => u.Id.EndsWith(staff.UserId)).Select(u => u.UserName).FirstOrDefault();
                steps.Add(new StepVo($"用户发起 [ {userNames} ]", $" [理由] {workFlow_Instance.ReviewReason}"));
            }

            //部门经理
            Text manager = managers.OrderByDescending(r => r.CreateTime).FirstOrDefault();
            if (manager != null)
            {
                WorkFlow_InstanceStep workFlow_Instance = _workFlow_InstanceSetpDal.getEntitys().FirstOrDefault(w => w.Id.EndsWith(manager.InstanceSetId));
                string userNames = _userDAL.getUserShowDAL().Where(u => u.Id.EndsWith(manager.UserId)).Select(u => u.UserName).FirstOrDefault();
              
                if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.REJECTED == workFlow_Instance.ReviewStatus)
                {
                    //获取当前步骤部门经理名称
                    steps.Add(new StepVo($"部门经理 [ {userNames} ]", $" [驳回] {workFlow_Instance.ReviewReason}"));
                    stepVos.Status = status-=1;
                }
                else if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.AGREE == workFlow_Instance.ReviewStatus)
                {
                    //获取当前步骤部门经理名称
                    steps.Add(new StepVo($"部门经理 [ {userNames} ]", $" [同意] {workFlow_Instance.ReviewReason}"));
                    stepVos.Status = status += 1;
                }
                else if (WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.EXAMINATION == workFlow_Instance.ReviewStatus)
                {
                    //获取当前步骤部门经理名称
                    steps.Add(new StepVo($"部门经理 [ {userNames} ]", "审核中"));
                }

            }

            //仓库管理
            Text warehouse = warehouses.OrderByDescending(r => r.CreateTime).FirstOrDefault();
            if (warehouse != null)
            {
                WorkFlow_InstanceStep workFlow_Instance = _workFlow_InstanceSetpDal.getEntitys().FirstOrDefault(w => w.Id.EndsWith(warehouse.InstanceSetId));
                //获取当前步骤仓库管理名称
                string userNames = _userDAL.getUserShowDAL().Where(u => u.Id.EndsWith(warehouse.UserId)).Select(u => u.UserName).FirstOrDefault();
            
                if (workFlow_Instance.ReviewStatus== WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.REJECTED)
                {
                    steps.Add(new StepVo($"仓库管理 [ {userNames} ]", $" [驳回] {workFlow_Instance.ReviewReason} "));
                }
                else if (workFlow_Instance.ReviewStatus == WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.EXAMINATION)
                {
                    steps.Add(new StepVo($"仓库管理 [ {userNames} ]", "审核中"));
                }
                else if (workFlow_Instance.ReviewStatus == WorkFlow_InstanceEnums.WorkFlow_InstanceStepEnums.AGREE)
                {
                    steps.Add(new StepVo($"仓库管理 [ {userNames} ]", workFlow_Instance.ReviewReason ));
                }
            }
            else
            {
                steps.Add(new StepVo($"仓库管理", "未审核"));
            }
          

            //结束 
            steps.Add(new StepVo("结束", "未结束"));

            //赋值
            stepVos.Step = steps;

            return stepVos;
        }

        /// <summary>
        /// 修改页面数据
        /// </summary>
        /// <param name="instanceSteID">步骤id</param>
        /// <returns></returns>
        public object getUpdataWorkFlow_InstanceSteptList(string instanceSteID)
        {
            return Linked(null, instanceSteID).FirstOrDefault();
        }

        /// <summary>
        /// 获取实例日志信息
        /// </summary>
        /// <param name="InstanceId"></param>
        /// <returns></returns>
        public object getLogList(string instanceId)
        {
            List<WorkFlow_InstanceStep> workFlow_Instance= _workFlow_InstanceSetpDal.getEntitys().Where(w => w.InstanceId.EndsWith(instanceId)).ToList();
            List<LogVo> logs = new List<LogVo>(); 
            foreach (var item in workFlow_Instance)
            {
                string userName= _userDAL.getUserShowDAL().Where(u => u.Id.EndsWith(item.ReviewerId)).Select(u => u.UserName).FirstOrDefault();
                logs.Add(new LogVo(userName, item.ReviewReason, item.CreateTime, item.ReviewStatus));
            }
            return logs.OrderByDescending(l=>l.CreateTime);
        }
    }
}